package com.study;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * @author sjw
 * @description
 * @date 2019-08-19 下午5:02
 */
public class MqUtil {
    public static void main(String[] args) {
        Connection connection = null;
        Channel channel = null;
        try {
            ConnectionFactory factory = new ConnectionFactory();
            factory.setHost("192.168.10.66");
            //factory.setHost("192.168.0.27");
            //factory.setHost("39.106.17.245");
            factory.setVirtualHost("/");
            factory.setUsername("root");
            factory.setPassword("123456");
            connection = factory.newConnection();
            channel = connection.createChannel();
            User user = new User();
            for (int i = 0; i < 100; i++) {
                user.setId(i);
                user.setName("name" + i);
                channel.basicPublish("e.study", "flink", null, JsonHelper.objectToJson(user).getBytes("UTF-8"));
                //Thread.sleep(10*1000);
            }
            //channel.basicPublish("e.study", "flink", null, "qw".getBytes("UTF-8"));


        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (connection != null) {
                try {
                    connection.close();
                } catch (Exception ignore) {
                }
            }
        }
    }
}
